package com.biz.primus.ms.oms.jpa;

import com.biz.primus.common.utils.JsonUtils;
import com.biz.primus.model.oms.vo.OmsOrderReturnVo;
import lombok.extern.slf4j.Slf4j;

import javax.persistence.AttributeConverter;

/**
 * @author yanweijin
 * @date 2017/11/14
 */
@Slf4j
public class ReturnOriginDataWithJSONConverter implements AttributeConverter<OmsOrderReturnVo, String> {
	@Override
	public String convertToDatabaseColumn(OmsOrderReturnVo attribute) {
		try{
			return JsonUtils.obj2Json(attribute);
		}catch (Exception e){
			log.warn("订单收单原始数据转换为json失败",e);
			return null;
		}
	}

	@Override
	public OmsOrderReturnVo convertToEntityAttribute(String dbData) {
		try{
			return JsonUtils.json2Obj(dbData, OmsOrderReturnVo.class);
		}catch (Exception e){
			log.warn("订单收单原始数据反序列化为对象失败",e);
			return null;
		}
	}
}
